package com.cn.onetrip.untility;

import io.vov.utils.Log;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.cn.onetrip.objects.AdvertsObj;
import com.cn.onetrip.objects.ArticleListObj;
import com.cn.onetrip.objects.ArticleObj;
import com.cn.onetrip.objects.AtlasObj.PictureObj;
import com.cn.onetrip.objects.ContentObj;
import com.cn.onetrip.objects.InfosListObj;
import com.cn.onetrip.objects.LarkObj;
import com.cn.onetrip.objects.NotesListObj;
import com.cn.onetrip.objects.RouteObj;
import com.cn.onetrip.objects.VideosMediaObj;
import com.cn.onetrip.objects.VisitsListObj;
import com.cn.onetrip.objects.WeatherObj;

import android.app.Application;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.os.Environment;

public class SysApplication extends Application {

	public Context mContext;

	public static final int POP_NUM = 24;
	public static Bitmap bmpGrey = null;
	public static Bitmap bmpColor = null;
	public static Bitmap bmpRoute = null;
	public static int bmpWidth = 0;
	public static int bmpHeight = 0;

	public static HashMap<String, Drawable> adCache = new HashMap<String, Drawable>();

	public static WeatherObj weatherObj = new WeatherObj();

	public static ContentObj contentObj = new ContentObj();

	public static List<VideosMediaObj> videoList = new ArrayList<VideosMediaObj>();

	public static List<LarkObj> larkList = new ArrayList<LarkObj>();

	public static List<AdvertsObj> advertsList = new ArrayList<AdvertsObj>();

	public static List<PictureObj> slidesList = new ArrayList<PictureObj>();

	public static List<NotesListObj> notesList = new ArrayList<NotesListObj>();

	public static List<ArticleListObj> articlesListObj = new ArrayList<ArticleListObj>();

	public static List<VisitsListObj> visitsListObj = new ArrayList<VisitsListObj>();

	public static List<RouteObj> routesList = new ArrayList<RouteObj>();

	public static Map<String, List<InfosListObj>> infosMapList = new HashMap<String, List<InfosListObj>>();

	public static Map<String, ArticleObj> articleMap = new HashMap<String, ArticleObj>();

	public static String Json1Path = Environment.getExternalStorageDirectory()
			.getAbsolutePath() + "/tmp/json1.txt";

	public static String Json2Path = Environment.getExternalStorageDirectory()
			.getAbsolutePath() + "/tmp/json2.txt";

	public SysApplication(Context context) {
		this.mContext = context;
	}

	public void addVideos(VideosMediaObj videoObj) {
		videoList.add(videoObj);
	}

	public void addLarks(LarkObj larkObj) {
		larkList.add(larkObj);
	}

	public void addAdverts(AdvertsObj advertsObj) {
		advertsList.add(advertsObj);
	}

	public void addSlides(PictureObj picObj) {
		slidesList.add(picObj);
	}

	// public void addInfos(InfosListObj infoObj) {
	// infosList.add(infoObj);
	// }

	public void addInfosList(String key, List<InfosListObj> list) {
		infosMapList.put(key, list);
	}

	public void addNotesList(NotesListObj notesListObj) {
		notesList.add(notesListObj);
	}

	public void addArticlesList(ArticleListObj articleListObj) {
		articlesListObj.add(articleListObj);
	}

	public void addVisitsList(VisitsListObj visitListObj) {
		visitsListObj.add(visitListObj);
	}

	public void addRoutesList(RouteObj routeObj) {
		routesList.add(routeObj);
	}

	public void clearData() {
		adCache.clear();
		videoList.clear();
		larkList.clear();
		advertsList.clear();
		slidesList.clear();
		notesList.clear();

		articlesListObj.clear();
		visitsListObj.clear();
		routesList.clear();
		infosMapList.clear();
		articleMap.clear();

	}

	public static void recycleBmps() {
		recycleBmpGrey();
		recycleBmpColor();
		recycleBmpRoute();
	}

	public static void recycleBmpGrey() {
		if (bmpGrey != null && !bmpGrey.isRecycled()) {
			bmpGrey.recycle();
			bmpGrey = null;
			Log.i("recycle bmpGrey");
		}

		System.gc();
	}

	public static void recycleBmpColor() {
		if (bmpColor != null && !bmpColor.isRecycled()) {
			bmpColor.recycle();
			bmpColor = null;
			Log.i("recycle bmpColor");
		}

		System.gc();
	}

	public static void recycleBmpRoute() {
		if (bmpRoute != null && !bmpRoute.isRecycled()) {
			bmpRoute.recycle();
			bmpRoute = null;
			Log.i("recycle bmpRoute");
		}

		System.gc();
	}

}
